// pages/equipment/add/add.js
import {
  validate
} from '../../../../../common/js/validate'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '请选择就诊日期',
    time: '请选择就诊时间',
    medical: '请选择就诊医护',
    mark: '',
    disabledSubmit: true,
    optionsMedical: [{
        label: "张医生",
        value: "张医生"
      },
      {
        label: "王医生",
        value: "王医生"
      },
      {
        label: "孙医生",
        value: "孙医生"
      },
      {
        label: "李医生",
        value: "李医生"
      },
      {
        label: "周医生",
        value: "周医生"
      },
      {
        label: "吴医生",
        value: "吴医生"
      },
    ],
    btnText: '提交预约',
    from: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      from: options.from
    })
    if (options.btnText) {
      this.setData({
        btnText: decodeURIComponent(options.btnText)
      })
    }
  },
  showModal(e) {
    const id = e.currentTarget.dataset.id
    this.selectComponent('#' + id).show()
  },
  bindTimeChange(e) {
    this.setData({
      time: e.detail.value
    })
    this.updateButtonStatus()
  },
  bindDateChange(e) {
    this.setData({
      date: e.detail.value
    })
    this.updateButtonStatus()
  },
  /**
   * 输入事件
   */
  bindinput(e) {
    const name = e.currentTarget.dataset.name
    this.setData({
      [name]: e.detail.value,
    })
  },
  updateButtonStatus() {
    this.setData({
      disabledSubmit: !(this.data.date && this.data.time && this.data.medical)
    })
  },
  bindChange(e) {
    let name = e.currentTarget.dataset.name
    let value = e.detail.value
    this.setData({
      [name]: value
    })
    this.updateButtonStatus()
  },
  bindtapNext() {
    if (this.data.disabledSubmit) {
      return
    }
    const {
      from,
      name,
      mobile,
      certificate,
      medical,
      department,
      mark
    } = this.data
    validate(this, 'name', 'mobile')

    if (from == 'referralService') {
      this.selectComponent('#referralServiceDialog').show()
    } else if (from == 'appointmentReferral') {
      this.selectComponent('#appointmentReferralDialog').show()
    } else {
      wx.navigateTo({
        url: '/pages/appointmentReferral/fee/fee',
      })
    }
  }
})